cmake_minimum_required(VERSION 3.21)

set(PROJECT_NAME 22_excercise)

project(${PROJECT_NAME})

# 在项目中加入一个全局的预编译宏
add_definitions(-DDEBUG)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/thirdParty/include)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/include)

add_subdirectory(wrapper/)
add_subdirectory(application/)
add_subdirectory(glframework/)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  set(COMPILER_TYPE "gcc")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  set(COMPILER_TYPE "clang")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  set(COMPILER_TYPE "msvc")
endif()

link_directories(
  SYSTEM
  ${CMAKE_SOURCE_DIR}/thirdParty/lib/${CMAKE_SYSTEM_NAME}/${COMPILER_TYPE})

# add_compile_options(-I"${CMAKE_SOURCE_DIR}/thirdParty/include")
set(BIN_DIR ${CMAKE_SOURCE_DIR}/build/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BIN_DIR})

# file(GLOB ASSETS "./assets") file(COPY ${ASSETS} DESTINATION
# ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

add_executable(${PROJECT_NAME} "main.cpp" "glad.c")

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  # Windows平台逻辑
  if(COMPILER_TYPE STREQUAL "msvc")
    set(LIB_NAME "glfw3.lib")
  elseif(COMPILER_TYPE STREQUAL "clang")
    set(LIB_NAME "libglfw3.a")
  elseif(COMPILER_TYPE STREQUAL "gcc")
    set(LIB_NAME "libglfw3.a")
  endif()

elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  # Linux平台逻辑
  if(COMPILER_TYPE STREQUAL "clang")
    set(LIB_NAME "libglfw3.a")
  elseif(COMPILER_TYPE STREQUAL "gcc")
    set(LIB_NAME "libglfw3.a")
  endif()

endif()

target_link_libraries(app ${LIB_NAME})
target_link_libraries(${PROJECT_NAME} wrapper app fw)

#[[ add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy_directory "${CMAKE_SOURCE_DIR}/assets"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/assets" VERBATIM) COMMAND_EXPAND_LISTS) ]]

add_custom_command(
  TARGET ${PROJECT_NAME}
  POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/assets"
          "$<TARGET_FILE_DIR:${PROJECT_NAME}>/assets"
  COMMAND_EXPAND_LISTS VERBATIM)
# get_target_property(DEPS ${PROJECT_NAME} LINK_LIBRARIES) message(STATUS
# "依赖库列表: ${DEPS}")
